/**
 * @param {Node} head
 * @return {Node}
 */
 function copyRandomList (head) {
    if (!head) return head;
    let node = head;
    while(node) {
        const copyNode = new Node(node.val, node.next, null);
        node.next = copyNode;
        node = copyNode.next;
    }
    node = head;
    while(node) {
        const copyNode = node.next;
        copyNode.random = node.random !== null ? node.random.next : null;
        node = copyNode.next;
    }
    const res = head.next;
    node = head;
    while(node) {
        const copyNode = node.next;
        node.next = node.next.next;
        copyNode.next = copyNode.next !== null ? copyNode.next.next : null;
        node = node.next;
    }
    return res;
};
